package com.ideaaedi.component.decompile.fernflower;

import org.jetbrains.java.decompiler.main.extern.IResultSaver;

import java.util.LinkedHashMap;
import java.util.jar.Manifest;

/**
 * 基于内存的接收器
 *
 * @author JustryDeng
 * @since 2021/9/29 14:24:14
 */
public class MemoryResultSaver implements IResultSaver {
    
    /**
     * 反编译出来的<b>classFilePath</b>以及<b>源码</b>
     * <ul>
     *      <li>key - 源码对应class的classFilePath, 形如com/szlzcl/jdk8feature/OptionalTests$MyConsumer.class</li>
     *      <li>value - 源码</li>
     * </ul>
     */
    private final LinkedHashMap<String, String> sourceCodeMap = new LinkedHashMap<>(8);
    
    @Override
    public void saveFolder(String path) {
    
    }
    
    @Override
    public void copyFile(String source, String path, String entryName) {
    
    }
    
    /**
     * 保存反编译结果
     *
     * @param qualifiedName
     *         以斜杠分割的全类名，形如 com/szlaozicl/mybatisplusdemo/tmp/ScheduleConfig
     * @param entryName
     *         待反编译的class文件的文件名，只是将后缀.class替换为了.java, 如: ScheduleConfig.java
     * @param content
     *            源码
     * @param mapping
     *            行号映射
     */
    @Override
    public void saveClassFile(String path, String qualifiedName, String entryName, String content, int[] mapping) {
        sourceCodeMap.put(qualifiedName + ".class", content);
    }
    
    @Override
    public void createArchive(String path, String archiveName, Manifest manifest) {
    
    }
    
    @Override
    public void saveDirEntry(String path, String archiveName, String entryName) {
    
    }
    
    @Override
    public void copyEntry(String source, String path, String archiveName, String entry) {
    
    }
    
    @Override
    public void saveClassEntry(String path, String archiveName, String qualifiedName, String entryName,
                               String content) {
        
    }
    
    @Override
    public void closeArchive(String path, String archiveName) {
    
    }
    
    /**
     * 获取源码信息
     *
     * @return 反编译出来的<b>classFilePath</b>以及<b>源码</b>
     * <ul>
     *      <li>key - 源码对应class的classFilePath, 形如com/szlzcl/jdk8feature/OptionalTests$MyConsumer.class</li>
     *      <li>value - 源码</li>
     * </ul>
     */
    public LinkedHashMap<String, String> getResult() {
        return this.sourceCodeMap;
    }
}
